package zzps.exeed.kernel.holder;

import java.util.Arrays;
import java.util.function.Consumer;

/**
 * 值收集器，用于通过方法实例化对象时收集方法参数值
 */
public class ValueGather {

    private ValueInjector[] valueInjectors;
    private Consumer<Object[]> consumer;

    public ValueGather(int length, Consumer<Object[]> consumer) {
        this.valueInjectors = new ValueInjector[length];
        this.consumer = consumer;
//        Arrays.stream(valueInjectors).forEach(varValue -> varValue.setVarValueGather(this));
    }

    public ValueInjector[] getValueInjectors(){
        return valueInjectors;
    }
    public void run() {
        for (ValueInjector valueInjector : valueInjectors) {
            if (!valueInjector.ready()){
                return;
            }
        }
        Object[] array = Arrays.stream(valueInjectors).map(varValue -> varValue.getValue()).toArray();
        consumer.accept(array);
    }
}
